package model;

import java.io.Serializable;

import model.exceptions.*;

import common.ClientInterface;

public class User implements Serializable {
	private String name;
	protected String password;
	private int score;
	private ClientInterface client;

	public User(String name, String password, ClientInterface client) {
		this.name = name;
		this.password=password;
		this.client=client;
	}

	public String getName() {
		return name;
	}
	
	public void login(String password, ClientInterface client) throws AbstractException {
		if(!this.password.equals(password))
			throw new WrongPasswordException();
		if(this.client!=null)
			throw new UserAlreadyLoggedinException();
		this.client=client;
	}
	
	public void logout() {
		client=null;
	}
	
	public int getScore() {
		return score;
	}
	
	public ClientInterface getInterface() {
		return client;
	}
	
	public boolean equals(Object obj) {
		if(!(obj instanceof User))
			return false;
		User other=(User) obj;
		return this.name.equals(other.getName());
	}
}